package utils
{
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.ui.Mouse;

	public class Coursor extends Sprite
	{
		[Embed(source="assets/coursor/left.png")]
		private var leftCls:Class;
		[Embed(source="assets/coursor/right.png")]
		private var rightCls:Class;
		[Embed(source="assets/coursor/rotationCls.png")]
		private var rotationCls:Class;
		[Embed(source="assets/coursor/move.png")]
		private var moveCls:Class;
		
		private var bitmap:Bitmap;
		public var container:Sprite;
		private static var instance:Coursor; 
		public function Coursor()
		{
			if(instance!=null) throw new Error("Error: Singletons can only be instantiated via getInstance() method!");  
			Coursor.instance = this;  
		}
		public static function getInstance():Coursor  
		{  
			if(instance==null)  instance = new Coursor();  
			return instance; 
		}
		
		public function showCoursor(type:String):void{
			this.addEventListener(Event.ENTER_FRAME,onEnter);
			if(bitmap && bitmap.parent)
				container.removeChild(bitmap);
			Mouse.hide();
			switch(type){
				case "left" :
					bitmap = new leftCls();
					break
				case "right" :
					bitmap = new rightCls();
					break
				case "move" :
					bitmap = new moveCls();
					break
				case "rotation" :
					bitmap = new rotationCls();
					break
			}
			container.addChild(bitmap);
		}
		private function onEnter(event:Event):void{
			bitmap.x = container.mouseX - 8;
			bitmap.y = container.mouseY - 8;
		}
		public function removeCoursor():void{
			this.removeEventListener(Event.ENTER_FRAME,onEnter);
			if(bitmap.parent)
				container.removeChild(bitmap);
			Mouse.show();
		}
		
	}
}